package com.example.demo.services.impl;

import com.example.demo.dao.YGRepository;
import com.example.demo.entity.YG;
import com.example.demo.services.YGService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YGServiceImpl implements YGService {

    @Autowired
    private YGRepository ygRepository;

    @Override
    public YG getYG(String username, String password) {
        return ygRepository.findByYnoAndYpw(username, password);
    }

    /**
     * @Author: Ding XiJie
     * @Description: 添加收货人
     */
    @Override
    public YG save(YG yg) {
        yg = ygRepository.save(yg);
        return yg;
    }

    /**
     * @Author: Ding XiJie
     * @Description: 修改收货人
     */
    @Override
    public YG update(YG yg) {
        return ygRepository.save(yg);
    }

    /**
     * @Author: Ding XiJie
     * @Description: 删除收货人
     */
    @Override
    public void delete(int id) {
        ygRepository.deleteById(id);
    }

    @Override
    public List<YG> getAllYg() {
        return ygRepository.findAll();
    }

    @Override
    public Integer findCount() {
        Long count = ygRepository.count();
        Integer countInt = count.intValue();
        return countInt;
    }
}
